﻿
@{
    
}
<script src="~/Scripts/jquery-3.4.1.slim.js"></script>

<audio id="yuyin" controls="controls"  ></audio>

<div>
    <input type="text" id="textv" value="再长的路，一步步也能走完" />
    <button name="langdu" id="langdu"> 朗读 </button>
</div>

<script>
    var hostUrl = "http://localhost:44384/api/values/Text2Vocie?text=";
    function TxtToSound(str) {
        var audio = document.getElementById('yuyin');
        $.get(hostUrl +  str, function (data) {
           
            var jsonResult = JSON.parse(data);
            console.log('获取数据');
            console.log(jsonResult);
            console.log(jsonResult.Result);
            if (true)//jsonResult.Result=='true'
            {
                var uurl = 'http://localhost:44384' + jsonResult.ReturnData;
                console.log(uurl);
                console.log('设置属性');
                $('#yuyin').attr('src', uurl);
                audio.play();
            }
            console.log('1111222');
        }, 'text');
    }
    $(function () {
        $('#langdu').click(function () {
            var _txt = $('#textv').val();
          
            console.log('开始转换');
            TxtToSound(_txt);
        });
    });
</script>

